﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.IO;
using System.Data;
public partial class CMS_Version : System.Web.UI.Page
{
    Usas.Model.Cms.cmsArticle artm = new Usas.Model.Cms.cmsArticle();
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.Common.Cms.FileControl fc = new Usas.Common.Cms.FileControl();
    Usas.BLL.Cms.cmsArticle art = new Usas.BLL.Cms.cmsArticle();
    Usas.BLL.Cms.UsasDB udb = new Usas.BLL.Cms.UsasDB();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                Bind();
            }
            catch
            {
            }
        }
    }

    private void Bind()
    {
        try
        {

            object artid = Request["id"];
            if (artid.ToString() != "")
            {
                //更新点击
                art.UpHits(Convert.ToInt32(artid));


                artm = art.GetModel(Convert.ToInt32(artid));

                lblTname.Text = artm.ArtTopic;

                hits.Text = "阅览数：" + artm.hits.ToString() + "　｜　";

                if (artm.Writer == 0)
                {
                    writer.Visible = false;
                }
                else
                {
                    DataSet zuozheds = udb.SelEmployees("EmployeeId=" + artm.Writer);
                    writer.Text = zuozheds != null && zuozheds.Tables[0].Rows.Count > 0 ? "作者：" + zuozheds.Tables[0].Rows[0]["EmpName"].ToString() + "　｜　" : "";
                }

                if (artm.Modify == 0)
                {
                    modfiy.Visible = false;
                }
                else
                {
                    DataSet zuozheds = udb.SelEmployees("EmployeeId=" + artm.Writer);
                    modfiy.Text = zuozheds != null && zuozheds.Tables[0].Rows.Count > 0 ? "文章录入：" + zuozheds.Tables[0].Rows[0]["EmpName"].ToString() + "　｜　" : "";
                }


                if (artm.ModfiyTime.ToString() == "")
                {
                    modfiytime.Visible = false;
                }
                else
                {
                    modfiytime.Text = "更新时间：" + artm.ModfiyTime.Value.ToString("yyyy-MM-dd") + "　｜　";
                }




                if (artm.ArtSummary.Trim().Length > 0)
                {
                    sum.Visible = true;
                    sumcontent.InnerText = "内容摘要：" + artm.ArtSummary.Trim();
                }
                else
                {
                    sum.Visible = false;
                }

                if (artm.ArtKeys.Trim().Length > 0)
                {
                    artkey.Visible = true;
                    artkey.InnerHtml = "关键字：<span style='font-weight:bold;color:red'>" + artm.ArtKeys.Trim() + "</span>";
                }
                else
                {
                    artkey.Visible = false;
                }

                string temppath = ConfigurationSettings.AppSettings["UsasInformationPath"];
                if (temppath.IndexOf(":") == -1)
                {
                    temppath = MapPath(temppath + "CMSUpLoadFiles\\" + artm.ArtDirectory + "\\" + artm.ArtFileName);
                }
                else
                {
                    temppath += "CMSUpLoadFiles\\" + artm.ArtDirectory + "\\" + artm.ArtFileName;
                }

                //保密
                bool adit = false;
                adit = (adit ? adit : !artm.Audit);

                if (artm.ArtFormat != 2)
                {
                    //lb.Text = "点击此处";
                    FileInfo fn = new System.IO.FileInfo(temppath);

                    fc.OnlySee(pn, true, artm.ArtDirectory.Replace("\\", "/") + "/" + artm.ArtFileName, Path.GetExtension(temppath), adit);

                    FileContent.Visible = false;
                    Plus.Visible = true;
                }
                else
                {
                    if (File.Exists(temppath))
                    {
                        string msg = File.ReadAllText(temppath, System.Text.Encoding.GetEncoding("UTF-8")).ToString();
                        FileContent.InnerHtml = msg;
                        // lb.Visible = false;
                        Plus.Visible = false;
                    }
                    else
                    {
                        FileContent.Visible = false;
                        // lb.Visible = false;
                        Plus.Visible = false;
                    }
                }

                //ReViewBox1.ChatBoxInit(Convert.ToInt32(artm.ArtId), artm.ArtTopic, check);

            }
        }
        catch
        {
            //ViewControlBar1.IntiControl(false, "", "", "");
        }
    }



}
